package com.shenzhen.horselive.ui.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;

import com.flqy.baselibrary.utils.GlideHelper;
import com.king.zxing.util.CodeUtils;
import com.shenzhen.horselive.R;
import com.shenzhen.horselive.User;
import com.shenzhen.horselive.api.ApiFactory;
import com.shenzhen.horselive.base.AppBarActivity;
import com.shenzhen.horselive.beans.KeFuBeans;
import com.shenzhen.horselive.databinding.ActivityKeFuWeChatBinding;
import com.shenzhen.horselive.network.SchedulersCompat;
import com.shenzhen.horselive.presenter.LoadingViewObserver;
import com.shenzhen.horselive.utils.A;

public class KeFuWeChatActivity extends AppBarActivity {

    ActivityKeFuWeChatBinding  binding;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityKeFuWeChatBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        setStyleDark();
        setTitle("联系客服");
        initViews();
    }

    private void initViews() {
        ApiFactory.getApiService().getWeChat(User.get().getMyInfo().getToken())
                .compose(SchedulersCompat.applyIoSchedulers())
                .safeSubscribe(new LoadingViewObserver<KeFuBeans>(this) {
                    @Override
                    protected void onNextInActive(KeFuBeans keFuBeans) {
                        if (keFuBeans.isSuccess())
                        {
                           if (keFuBeans.getData()!=null)
                           {
                               coedeIntoImageView(keFuBeans.getData());
                           }

                        }else
                        {
                            showToast(keFuBeans.getErrMessage());
                        }
                    }
                });
    }
    private void coedeIntoImageView(String url) {
        //生成二维码
        Bitmap bitmap =  CodeUtils.createQRCode(url,200);
        if (bitmap!=null)

        {
            binding.imgCode.setImageBitmap(bitmap);
//            Bitmap bitmap1 = ((BitmapDrawable)getResources().getDrawable(R.mipmap.ico_kefu_backgroud)).getBitmap();
//            A.QRCodeCompose  codeCompose = new A.QRCodeCompose();
//            Bitmap  bitmap2 =   codeCompose.composeQrCodeBitmapByTransparentArea(bitmap1,bitmap, A.TransparentScanDirection.左上方);
//            binding.imgImg.setImageBitmap(bitmap2);
        }
//        binding.imgCode.setImageBitmap(bitmap);
    }



}


